﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................
namespace QLKTX1._0.DAO
{
    class HocKyDAO
    {
        public static List<HocKyDTO> dsHocKy()
        {
            List<HocKyDTO> dsHocKy = new List<HocKyDTO>();

            ConnectDB con = new ConnectDB();

            DataTable dt = con.getDataTable("SELECT * FROM hocKy");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                HocKyDTO hocky = new HocKyDTO();
                hocky.MaHocKy = dt.Rows[i]["maHocKy"].ToString();
                hocky.TenHocKy = dt.Rows[i]["tenHocKy"].ToString();
                dsHocKy.Add(hocky );
            }
            return dsHocKy ;
        }
        //Ham Insert
        public static bool themHocKy(HocKyDTO hocKy)
        {

            ConnectDB con = new ConnectDB();// dung DB

            return con.executeQuery("INSERT INTO hocKy(maHocKy,tenHocKy) VALUES('" + hocKy.MaHocKy + "','" + hocKy.TenHocKy + "')");

        }
        //Ham Delete
        public static bool xoaHocKy(HocKyDTO hocKy)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM hocKy WHERE maHocKy='" + hocKy.MaHocKy + "'");
        }
        //Ham Update
        public static bool capNhatHocKy(HocKyDTO hocKy)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE hocKy set tenHocKy='" + hocKy.TenHocKy + "' WHERE maHocKy='" + hocKy.MaHocKy + "'");
        }
    }
}
